
package mdoc.ejbsample;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.NamedQuery;
import javax.persistence.NamedQueries;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.persistence.CascadeType;

import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name="FILMS", schema = "test")
@NamedQueries({
	@NamedQuery(name = "findAllFilms",   query = "select f from Film f"),
	@NamedQuery(name = "findFilmByName", query = "select f from Film f WHERE f.name = :fname")
		})
public class Film implements java.io.Serializable {
	private static final long serialVersionUID = -2L;;


	@Id @GeneratedValue(strategy = GenerationType.AUTO)
	private int             id;
	private String          name;

	@OneToMany(mappedBy = "film", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
	private Set<SalleProg> salles;


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}


	public HashSet<SalleProg> getSalles() {
		return new HashSet<SalleProg>(salles);
	}

	@Override public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Film[id=").append(getId()).append(", name=").append(getName()).append("]");
		return sb.toString();
	}
}
